<template>
  <div class="home">
    <el-container class="main-container">
      <el-header class="header">
        <el-menu
          :default-active="activeIndex"
          class="nav-menu"
          mode="horizontal"
          @select="handleSelect"
          :router="true"
          background-color="transparent"
          text-color="#ffffff"
          active-text-color="#ffffff"
        >
          <el-menu-item index="main" class="nav-item">首页</el-menu-item>
          <el-menu-item index="huntfor" class="nav-item">搜索</el-menu-item>
          <el-menu-item index="announcement" class="nav-item">公告</el-menu-item>
        </el-menu>
        <!-- 后台按钮 -->
        <el-button
          class="admin-button"
          @click="goToAdminPage"
          type="primary"
          size="large"
        >
          后台管理
        </el-button>
      </el-header>
      <el-main class="main-content">
        <router-view></router-view>
      </el-main>
    </el-container>
        <!-- 备案号 -->
        <div class="footer-beian">
      <a href="https://beian.miit.gov.cn/" target="_blank">粤ICP备2025367079号-1</a>
    </div>
    <!-- 收藏对话框 -->
  </div>
</template>

<script>
import request from "@/utils/request";
import router from "@/router";
import store from "@/store";
import { ElMessage } from "element-plus";
import articleApi from "@/api/article";
import { format } from "date-fns";
export default {
  data() {
    return {
      activeIndex: "main",
      storeArticles: [],
      store_dialogVisible: false,
    };
  },
  created() {},
  methods: {
    handleSelect(key, keyPath) {
      console.log(key);
      router.push({ path: key });
    },
    goToReleasePage() {
      this.$router.push({ name: "release" }); // 跳转到名为 'release' 的路由
    },
    goToStore() {
      this.store_dialogVisible = true;
      articleApi
        .getStoreList()
        .then((res) => {
          this.storeArticles = res.data;
        })
        .catch((res) => {
          console.log(res);
        });
    },
    formatDate(dateString) {
      return format(new Date(dateString), "yyyy-MM-dd HH:mm:ss");
    },
    home_to_articleDetail(id) {
      this.$router.push({ name: "articleDetail", query: { articleId: id } });
    },
    // 跳转到后台页面
    goToAdminPage() {
      // 使用路径进行导航
      this.$router.push('/Login');  // 使用路径来跳转
    },
  },
  compute: {},
  watch: {
  '$route'(to) {
    this.activeIndex = to.name || 'main';
  }
},
};
</script>
<style scoped>
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  width: 100%;
}

.home {
  min-height: 100vh;
  width: 100vw;
  background: linear-gradient(135deg, #636FA4  0%, #f2ab91 100%);
  background-attachment: fixed;
  background-size: cover;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin; /* Firefox */
  scrollbar-color: rgba(255, 255, 255, 0.3) rgba(255, 255, 255, 0.1); /* Firefox */
}

.main-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  width: 80%;
  margin: 0 auto;
  min-height: 100vh;
  position: relative;
}

.el-header {
  height: 70px;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  margin-top: 20px;
  border-radius: 15px;
  position: sticky;
  top: 20px;
  z-index: 100;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
  transition: all 0.3s ease;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 20px;
}

.el-header:hover {
  background: rgba(255, 255, 255, 0.2);
  transform: translateY(-2px);
}

.nav-menu {
  background: transparent;
  border: none;
  height: 70px;
  line-height: 70px;
  display: flex;
  width: 100%; /* 修改为 100% 宽度 */
  overflow: visible; /* 去掉溢出隐藏 */
  white-space: nowrap; /* 防止换行 */
}

.nav-item {
  height: 70px !important;
  line-height: 70px !important;
  font-size: 16px !important;
  color: #fff !important;
  padding: 0 25px !important;
  transition: all 0.3s ease !important;
  background: transparent !important;
}

.nav-item:hover {
  background: rgba(255, 105, 180, 0.8) !important; /* 鼠标悬浮时的粉色背景 */
  color: #fff !important;
}

:deep(.el-menu--horizontal > .el-menu-item.is-active) {
  background-color: #ff69b4 !important; /* 选中状态为粉色背景 */
  color: #fff !important;
  border-bottom: none !important;
}

:deep(.el-menu--horizontal) {
  border-bottom: none !important;
}

:deep(.el-menu--horizontal > .el-menu-item) {
  border-bottom: none !important;
}

.admin-button {
  position: absolute;
  right: 20px;
  top: 15px;
  height: 40px;
  padding: 0 25px;
  border-radius: 20px;
  font-size: 15px;
  background: linear-gradient(45deg, #ff9a9e 0%, #fad0c4 99%, #fad0c4 100%);
  border: none;
  color: white;
  transition: all 0.3s ease;
}

.admin-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2);
}

.el-main {
  flex: 1;
  padding: 30px 0;
  position: relative;
  z-index: 1;
  padding-bottom: 100px; /* 为固定底部留出空间 */
}

.el-footer {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 80%;
  height: 60px;
  margin: 20px 0;
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border-radius: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

@media screen and (max-width: 768px) {
  .main-container {
    width: 95%;
  }
  
  .nav-item {
    padding: 0 15px !important;
    font-size: 14px !important;
  }
  
  .admin-button {
    padding: 0 15px;
    font-size: 14px;
  }
}

/* 滚动条整体样式 */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

/* 滚动条轨道 */
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  margin: 5px;
}

/* 滚动条滑块 */
::-webkit-scrollbar-thumb {
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.3),
    rgba(255, 255, 255, 0.5)
  );
  border-radius: 10px;
  border: 2px solid transparent;
  background-clip: content-box;
  transition: all 0.3s ease;
}

/* 滚动条滑块悬浮效果 */
::-webkit-scrollbar-thumb:hover {
  background: linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.5),
    rgba(255, 255, 255, 0.7)
  );
  border: 2px solid transparent;
  background-clip: content-box;
}

/* 滚动条两端按钮 */
::-webkit-scrollbar-button {
  display: none;
}

/* 横向和纵向滚动条交汇处 */
::-webkit-scrollbar-corner {
  background-color: transparent;
}
.footer-beian {
  position: fixed;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  z-index: 1000;
  transition: opacity 0.3s ease;
}

.footer-beian:hover {
  opacity: 1;
}

.footer-beian a {
  color: inherit;
  text-decoration: none;
}

.footer-beian a:hover {
  text-decoration: underline;
}
</style>
